<template>
	<view>
		<view class="goods-item">
			<!-- item 左边图片 -->
			<view class="item-left">
				<radio :checked="goods.goods_state" color="#c00000" v-if="showRadio" @click="radioChange" />
				<image :src="goods.goods_small_logo || defaultPic"></image>
			</view>

			<!-- item 右边商品信息 -->
			<view class="item-info">
				<!-- 商品名字 -->
				<view class="goods-name">{{goods.goods_name}}</view>

				<!-- 商品价格 -->
				<view class="goods-price">
					<view>￥{{goods.goods_price | toFixNumber}}</view>
					<uni-number-box :min="1" :value="goods.goods_count" v-if="showNum" @change="numChangeHandler"></uni-number-box>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "my-goods",
		props: {
			goods: {
				type: Object,
				default: {}
			},
			showRadio: {
				type: Boolean,
				default: false
			},
			showNum: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
			};
		},
		filters: {
			toFixNumber(num) {
				return Number(num).toFixed(2)
			}
		},
		methods: {
			radioChange() {
				this.$emit('radioChange', {
					goods_id: this.goods.goods_id,
					goods_state: !this.goods.goods_state,
				})
			},
			numChangeHandler(newVal){
				this.$emit('numChange', {
					goods_id:this.goods.goods_id,
					goods_count: +newVal
				})
			}
		}
	}
</script>

<style lang="scss">
	.goods-item {
		display: flex;
		border: 1rpx solid #efefef;
		padding: 10rpx;
		box-shadow: 0 0 8rpx #606266;

		.item-left {
			display: flex;
			justify-content: space-between;
			align-items: center;

			image {
				width: 200rpx;
				height: 200rpx;
				margin-right: 10rpx;
				margin-left: 10rpx;
			}
		}

		.item-info {
			display: flex;
			flex: 1;
			flex-direction: column;
			justify-content: space-between;

			.goods-name {
				font-size: 28rpx;
			}

			.goods-price {
				display: flex;
				justify-content: space-between;
				align-items: center;
				color: #c00000;

				.uni-number-box {}
			}
		}
	}
</style>
